<template>
  <section class="cms-body" v-loading="loading">
    <!-- 返回组件 -->
    <cms-back></cms-back>
    <el-form ref="form" :model="dataInfo" :rules="rules" class="cms-form" label-width="162px">

      <el-form-item label="附件Id" class="flex-50" prop="attachmentId">
        <el-input v-model="dataInfo.attachmentId" class="cms-width" :disabled="true"></el-input>
      </el-form-item>

      <el-form-item label="附件类型" class="flex-50" prop="fileType">
        <el-select v-model="dataInfo.fileType" :disabled="true">
          <el-option label="图片" value="picture"></el-option>
          <el-option label="视频" value="video"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="附件名称" class="flex-50" prop="fileRemark">
        <el-input v-model="dataInfo.fileRemark" placeholder="图片说明" class="cms-width"></el-input>
      </el-form-item>
    </el-form>
    <div class="form-footer">
      <el-button type="primary" v-if="isType('update')" @click="update()" v-perms="'/keyword/update'">修改
      </el-button>
    </div>
  </section>
</template>
<script>
  import axios from "axios";
  import va from "@/rules";
  import formMixns from "@/mixins/form";

  export default {
    mixins: [formMixns],
    data() {
      let required = va.required();
      let number = va.number();
      return {
        rules: {//校验规则
          name: [required],
          position: [required, number]
        },
        dataInfo: {
          userId: '',
          filePath: 0,
          fileName: 0,
          fileRemark: '',
          fileType: '',
          fileSize: '',
          channelId: '',
          uploadWay: '',
          videoId: '',
          width: '',
          height: ''
        }
      };
    },
    methods: {
      getDataInfo(id) {
        axios.post(this.$api.attachmentGet, {attachmentId: id}).then(res => {
          console.log(res)
          this.loading = false;
          this.$refs["form"].resetFields();
          this.dataInfo = res.body; //将用户数据复制给dataInfo
        })
        this.loading = false;
      },
      update() {
        this.updateDataInfo(this.$api.attachmentUpdate, this.dataInfo, "pageList");
      }
    },
    created() {
      //初始获取数据
      this.getDataInfo(this.id);
    }
  };
</script>

<style>
</style>
